import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

public class Demo02 {
    public static void main(String[] args) {
//        System.out.println("430124198101070011:"+hasAdult("430124198101070011"));//true
//        System.out.println("430124202101070011:"+hasAdult("430124202101070011"));//false
        System.out.println("请输入18位身份证");
        Scanner sc=new Scanner(System.in);
        String a=sc.nextLine();
        System.out.println(a+":"+hasAdult(a));
    }
    public static boolean hasAdult(String a) {
        if(!a.matches("^\\d{17}[\\dX]$")) {
            throw new RuntimeException("18位的身份证号码不正确");
        }
        String ymd = a.substring(6,14);
        System.out.println(ymd);
        SimpleDateFormat f = new SimpleDateFormat("yyyyMMdd");
        try {
            Date d = f.parse(ymd);
            Calendar c = Calendar.getInstance();
            c.setTime(d);
            c.add(Calendar.YEAR, 18);
            System.out.println(f.format(c.getTime()));
            return new Date().after(c.getTime());
        } catch (ParseException e) {
            throw new RuntimeException("18位的身份证号码不正确");
        }
    }
}
